from next_level.Finance_Data.stock_plot_v5 import *

menu_str = ('Menu choices:\n' +
            '0. Exit\n' +
            '1. Simple Plot of Prices\n' +
            '2. Plot of Daily High/Low Prices\n' +
            '3. Plot of Price with Volume Subplot\n' +
            '4. Prices plus Moving Average\n')

prompt_msg = 'Enter stock symbol (ENTER to exit)'
def main():
    while True:
        # 提示用户输入直到用户输入了有效股票代码
        # 或者输入空值，应用程序终止
        try:
            s = input(prompt_msg)
            s = s.strip()     # 删除头尾空格
            if not s:    # 当字符串为空时退出
                break
            stock_df = load_stock(s)
            n = int(input(menu_str + 'Input choice: '))

            if n < 0 or n > 4:
                n = 0
            if n == 0:
                break

            fn = [do_simple_plot,do_highlow_plot,
                  do_volume_subplot,do_movingavg_plot][n-1]
            fn(stock_df,s)

        except:
            print('Couldn\'t find stock. Re-try.')

main()


